package com.talos.ums.enums;

import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Objects;

/**
 * 账号类型，内部账号-inner，货主账号-company，货主客户账号-company_customer，承运商账号-carrier，司机账号-driver，其他账号-other
 */
public enum AccountTypeEnum {

    INNER("inner", "内部账号"),
    COMPANY("company", "货主账号"),
    COMPANY_CUSTOMER("company_customer", "货主客户账号"),
    CARRIER("carrier", "承运商账号"),
    DRIVER("driver", "司机账号"),
    OTHER("other", "其他账号");

    @JsonValue
    private final String code;
    private final String msg;

    AccountTypeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 枚举类型转换，由于构造函数获取了枚举的子类enums，让遍历更加高效快捷
     *
     * @param code 数据库中存储的自定义code属性
     * @return code对应的枚举类
     */
    public static AccountTypeEnum codeOf(String code) {
        for (AccountTypeEnum status : AccountTypeEnum.values()) {
            if (Objects.equals(status.getCode(), code)) {
                return status;
            }
        }
        return null;
    }

}
